package cn.zysuyuan.item.service.impl;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.item.entity.MedicinalProductBase;
import cn.zysuyuan.item.entity.MedicinalProductBaseEdition;
import cn.zysuyuan.item.mapper.MedicinalProductBaseEditionMapper;
import cn.zysuyuan.item.service.MedicinalProductBaseEditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-02-18 12:56
 */

@Service
public class MedicinalProductBaseEditionServiceImpl implements MedicinalProductBaseEditionService {

    @Autowired
    private MedicinalProductBaseEditionMapper medicinalProductBaseEditionMapper;

    @Override
    public PageResult<MedicinalProductBaseEdition> selectList(Map<String, Object> map) {

        System.out.println("药品id：" + map.get("id"));
        /**
         * 将省市区组成地址
         */
        String bProvinceSeek = (String) map.get("bProvinceSeek");
        String bCitySeek = (String)map.get("bCitySeek");
        String bRegionSeek = (String)map.get("bRegionSeek");
        String bPosition = "";
        if(bProvinceSeek !=null && !"".equals(bProvinceSeek)){
            bPosition =bProvinceSeek;
        }
        if(bCitySeek !=null && !"".equals(bCitySeek)){
            bPosition =bPosition+"|"+bCitySeek;
        }
        if(bRegionSeek !=null && !"".equals(bRegionSeek)){
            bPosition =bPosition+"|"+bRegionSeek;
        }

        map.put("bPosition", bPosition);

        List<MedicinalProductBaseEdition> listTBH= this.medicinalProductBaseEditionMapper.selectList(map);   //获取表格数据信息

        /**
         * 将查询到的地址拆成省市区
         */
        if(listTBH != null && listTBH.size()>0){
            for(int i=0;i<listTBH.size();i++){
                String[] positions=listTBH.get(i).getbPosition().split("\\|");
                if(positions != null && positions.length>0){

                    for (int x=0;x<positions.length;x++){

                        switch(x){
                            case 0:
                                listTBH.get(i).setbProvince(positions[x]);
                                break;
                            case 1:
                                listTBH.get(i).setbCity(positions[x]);
                                break;
                            case 2:
                                listTBH.get(i).setbRegion(positions[x]);
                                break;
                        }
                    }
                }
                /**将|替换成空格*/
                listTBH.get(i).setbPosition(listTBH.get(i).getbPosition().replace("|", "  "));
            }
        }

        return new PageResult<MedicinalProductBaseEdition>(listTBH);
    }
}
